from abc import abstractmethod
from dataclasses import dataclass
import random
import re


@dataclass
class Equation:
    left: int
    right: int
    op: str
    rangeMin: int = 0
    rangeMax: int = 100

    def generateEquation(self, op: str):
        self.op = op
        self.left = random.randint(self.rangeMin, self.rangeMax)
        self.right = random.randint(self.rangeMin, self.rangeMax)

    def isBetween(self) -> bool:
        rs: int = self.calculate()
        return rs >= self.rangeMin and rs <= self.rangeMax

    def toStringNoAnswer(self) -> str:
        return f'{self.left}{self.op}{self.right}='

    @abstractmethod
    def calculate(self) -> int:
        pass

    @abstractmethod
    def isEquals(self, equation: any) -> int:
        pass

    @staticmethod
    def parse(equation: str):
        x = re.sub("[^0-9+-=]", "", equation)
